﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_EXSTOCK(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_EXSTOCK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_EXSTOCK(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_EXSTOCK(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertICC_EXSTOCK(dwData, 1);
            }
            UpdateICC_EXSTOCK(dwLocal);

        }
        public void InsertICC_EXSTOCK(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                #region=====无效=====
                case 1://20140501
                    or1.CommandText = "INSERT INTO ICC_EXSTOCK "
+ "(ROWNID,MANDANT,MONTH,LO,MART,MARTDES,MARTCOM,MVAR,MFARBE,PMART,TR00,VTR00,TR99,VTR99,TMCOST,TAB36,DTMCOSTTAB36,TR10,TR11,VTR10,DPRICE)"
+ " SELECT SEQ_ICC_ITX.NEXTVAL AS ROWNID,X.*"
+ " FROM (SELECT ICCGLMANDANT AS MANDANT,SUBSTR(MAX(ICCGLDAT),1,6) AS MONTH,ICCGLLO AS LO, B.GPGART AS MART,C.GSGARNBEZ AS MARTDES,'' AS MARTCOM,B.GPGVAR AS MVAR,B.GPGFARBE AS MFARBE,'' AS PMART,SUM(ICCGLBSTKG ) AS TR00,0 AS VTR00,0 AS TR99,0 AS VTR99,0 AS TMCOST,0 AS TAB36,0 AS DTMCOSTTAB36,0 AS TR10,0 AS TR11,0 AS VTR10,0 AS DPRICE"
+ " FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE  "
+ " LEFT JOIN GSDAT C ON  B.GPMANDANT = C.GSMANDANT AND B.GPGART = C.GSART AND B.GPGVAR = C.GSVAR"
+ " LEFT JOIN GSCOLOR D ON B.GPMANDANT = D.GSCMANDANT AND B.GPGART = D.GSCART AND B.GPGVAR = D.GSCVAR AND B.GPGFARBE=D.GSCFARBE "
+ " WHERE ICCGLMANDANT=:MANDANT AND ICCGLDAT=:MONTH   AND NOT EXISTS  (SELECT 1 FROM ICC_EXSTOCK S WHERE S.MONTH=SUBSTR(ICCGLDAT,1,6) AND S.LO=ICCGLLO AND S.MART=GPGART AND S.MVAR=GPGVAR AND S.MFARBE=GPGFARBE)"
+ " GROUP BY A.ICCGLMANDANT,ICCGLLO, B.GPGART,B.GPGVAR,C.GSGARNBEZ,B.GPGFARBE,D.GSCBEZ ) X ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 2://20140531
                    or1.CommandText = "  INSERT INTO ICC_EXSTOCK (ROWNID,MANDANT,MONTH,LO,MART,MARTDES,MARTCOM,MVAR,MFARBE,PMART,TR00,VTR00,TR99,VTR99,TMCOST,TAB36,DTMCOSTTAB36,TR10,TR11,VTR10,DPRICE,CONTROL)"
+ " SELECT SEQ_ICC_ITX.NEXTVAL AS ROWNID,X.*"
+ " FROM (SELECT ICCGLMANDANT AS MANDANT,SUBSTR(MAX(ICCGLDAT),1,6) AS MONTH,ICCGLLO AS LO, B.GPGART AS MART,C.GSGARNBEZ AS MARTDES,'' AS MARTCOM,B.GPGVAR AS MVAR,B.GPGFARBE AS MFARBE,'' AS PMART,"
+ " 0 AS TR00,0 AS VTR00,SUM(ICCGLBSTKG )  AS TR99,0 AS VTR99,0 AS TMCOST,0 AS TAB36,0 AS DTMCOSTTAB36,0 AS TR10,0 AS TR11,0 AS VTR10,0 AS DPRICE, '  ' AS CONTROL"
+ " FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE  "
+ " LEFT JOIN GSDAT C ON  B.GPMANDANT = C.GSMANDANT AND B.GPGART = C.GSART AND B.GPGVAR = C.GSVAR"
+ " LEFT JOIN GSCOLOR D ON B.GPMANDANT = D.GSCMANDANT AND B.GPGART = D.GSCART AND B.GPGVAR = D.GSCVAR AND B.GPGFARBE=D.GSCFARBE "
+ " WHERE ICCGLDAT='20140531' AND NOT EXISTS "
+ "  (SELECT 1 FROM ICC_EXSTOCK S WHERE S.MONTH=SUBSTR(ICCGLDAT,1,6) AND S.LO=ICCGLLO AND S.MART=GPGART AND S.MVAR=GPGVAR AND S.MFARBE=GPGFARBE)"
+ "  GROUP BY A.ICCGLMANDANT,ICCGLLO, B.GPGART,B.GPGVAR,C.GSGARNBEZ,B.GPGFARBE,D.GSCBEZ ) X ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                #endregion
                case 3:
                    or1.CommandText = "  INSERT INTO ICC_EXSTOCK (ROWNID,MANDANT,MONTH,LO,MART,MVAR,MARTDES )"
                    + " SELECT SEQ_ICC_ITX.NEXTVAL AS ROWNID,X.*"
                    + " FROM (SELECT DISTINCT ICCGLMANDANT AS MANDANT,:MONTH,ICCGLLO AS LO, B.GPGART AS MART,GPGVAR AS MVAR,C.GSGARNBEZ AS MARTDES"
                    + " FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE  "
                    + " LEFT JOIN GSDAT C ON  B.GPMANDANT = C.GSMANDANT AND B.GPGART = C.GSART AND B.GPGVAR = C.GSVAR"
                    + " WHERE  ICCGLMANDANT=:MANDANT AND SUBSTR(ICCGLDAT,1,6)=:MONTH AND NOT EXISTS "
                    + "  (SELECT 1 FROM ICC_EXSTOCK S WHERE S.MONTH=SUBSTR(ICCGLDAT,1,6) AND S.LO=ICCGLLO AND S.MART=GPGART AND S.MVAR=GPGVAR )"
                    + "  GROUP BY A.ICCGLMANDANT,ICCGLLO, B.GPGART,B.GPGVAR,C.GSGARNBEZ ) X ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 4:
                    or1.CommandText = "INSERT INTO ICC_EXSTOCK (ROWNID,MANDANT,MONTH,LO,MART,MVAR,MARTDES )"
                    + " SELECT SEQ_ICC_ITX.NEXTVAL AS ROWNID,X.*"
                    + " FROM (SELECT DISTINCT GABMANDANT AS MANDANT,:MONTH,GABLO AS LO, B.GPGART AS MART,B.GPGVAR AS MVAR,C.GSGARNBEZ AS MARTDES "
                    + "  FROM ICC_MGABEW A LEFT JOIN GPDAT B ON A.GABMANDANT = B.GPMANDANT AND A.GABPARTIE = B.GPPARTIE  "
                    + "  LEFT JOIN GSDAT C ON  B.GPMANDANT = C.GSMANDANT AND B.GPGART = C.GSART AND B.GPGVAR = C.GSVAR"
                    + "  WHERE  GABMANDANT=:MANDANT AND SUBSTR(GABBUCHDAT,1,6)=:MONTH AND NOT EXISTS "
                    + " (SELECT 1 FROM ICC_EXSTOCK S WHERE s.MANDANT=GABMANDANT AND S.MONTH= SUBSTR(GABBUCHDAT,1,6) AND S.LO=GABLO AND S.MART=GPGART AND S.MVAR=B.GPGVAR )"
                    + "  GROUP BY GABMANDANT,GABLO, B.GPGART,B.GPGVAR,C.GSGARNBEZ ) X ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public void DeleteICC_EXSTOCK(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_EXSTOCK  WHERE MANDANT=:MANDANT";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_EXSTOCK  WHERE MANDANT=:MANDANT  AND MONTH=:MONTH"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_EXSTOCK(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_EXSTOCK WHERE MANDANT=:MANDANT  AND MONTH=:MONTH"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_EXSTOCK WHERE MANDANT=:MANDANT  AND MONTH=:MONTH AND LO=:LO AND MART=:MART AND MVAR=:MVAR AND MFARBE=:MFARBE"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    or1.Parameters.Add("LO", OracleType.NVarChar).Value = dwData["LO"].ToString();
                    or1.Parameters.Add("MART", OracleType.NVarChar).Value = dwData["MART"].ToString();
                    or1.Parameters.Add("MVAR", OracleType.NVarChar).Value = dwData["MVAR"].ToString();
                    or1.Parameters.Add("MFARBE", OracleType.NVarChar).Value = dwData["MFARBE"].ToString();
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_EXSTOCK";
            Return = Result;
            return Return;
        }
        public void UpdateICC_EXSTOCK(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command====
                    or1.CommandText = "UPDATE ICC_EXSTOCK SET "
+ "COMPANY=:COMPANY,"
+ "USERID=:USERID,"
+ "PROCESS=:PROCESS,"
+ "MENUITEM=:MENUITEM,"
+ "MENUID=:MENUID,"
+ "FATHER=:FATHER,"
+ "HEADER=:HEADER,"
+ "TAG=:TAG,"
+ "ICON=:ICON,"
+ "LARGEICON=:LARGEICON,"
+ "JOB=:JOB,"
+ "TIMER=:TIMER,"
+ "SCHEDULETYPE=:SCHEDULETYPE,"
+ "FREQUENCY=:FREQUENCY,"
+ "TIME=:TIME "
+ " WHERE  "
+ "  MANDANT=:MANDANT AND ROWNID=:ROWNID";
                    #endregion

                    #region====Parameters====
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
                    or1.Parameters.Add("USERID", OracleType.NVarChar).Value = dwData["USERID"].ToString();
                    or1.Parameters.Add("PROCESS", OracleType.NVarChar).Value = dwData["PROCESS"].ToString();
                    or1.Parameters.Add("MENUITEM", OracleType.NVarChar).Value = dwData["MENUITEM"].ToString();
                    or1.Parameters.Add("MENUID", OracleType.NVarChar).Value = dwData["MENUID"].ToString();
                    or1.Parameters.Add("FATHER", OracleType.NVarChar).Value = dwData["FATHER"].ToString();
                    or1.Parameters.Add("HEADER", OracleType.NVarChar).Value = dwData["HEADER"].ToString();
                    or1.Parameters.Add("TAG", OracleType.NVarChar).Value = dwData["TAG"].ToString();
                    or1.Parameters.Add("ICON", OracleType.NVarChar).Value = dwData["ICON"].ToString();
                    or1.Parameters.Add("LARGEICON", OracleType.NVarChar).Value = dwData["LARGEICON"].ToString();
                    or1.Parameters.Add("JOB", OracleType.NVarChar).Value = dwData["JOB"].ToString();
                    or1.Parameters.Add("TIMER", OracleType.NVarChar).Value = dwData["TIMER"].ToString();
                    or1.Parameters.Add("SCHEDULETYPE", OracleType.NVarChar).Value = dwData["SCHEDULETYPE"].ToString();
                    or1.Parameters.Add("FREQUENCY", OracleType.NVarChar).Value = dwData["FREQUENCY"].ToString();
                    or1.Parameters.Add("TIME", OracleType.NVarChar).Value = dwData["TIME"].ToString();
                    #endregion
                    break;
                case 2:
                    or1.CommandText = "UPDATE ICC_EXSTOCK S SET TR00="
                    + "  (SELECT SUM(ICCGLBSTKG ) AS TR00 FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + "  WHERE ICCGLDAT=:SETDATE AND S.MANDANT=:MANDANT AND S.MONTH=:MONTH AND ICCGLLO<>'FI' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO  AND S.MART=GPGART AND S.MVAR=GPGVAR "
                    + "   GROUP BY MANDANT,MONTH,LO,MART,MVAR )"
                    + " WHERE EXISTS "
                    + " (SELECT 1 FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + " WHERE ICCGLDAT=:SETDATE AND S.MANDANT=:MANDANT  AND S.MONTH=:MONTH  AND ICCGLLO<>'FI' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO  AND S.MART=GPGART AND S.MVAR=GPGVAR)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    or1.Parameters.Add("SETDATE", OracleType.NVarChar).Value = dwData["SETDATE"].ToString();
                    break;
                case 21:
                    or1.CommandText = "UPDATE ICC_EXSTOCK S SET TR00="
                    + "  (SELECT SUM(ICCGLBSTKG ) AS TR00 FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + "  WHERE ICCGLDAT=:SETDATE AND S.MANDANT=:MANDANT AND S.MONTH=:MONTH AND ICCGLLO='FI' AND ICCGLLB='PR' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO  AND S.MART=GPGART  AND S.MVAR=GPGVAR"
                    + "   GROUP BY MANDANT,MONTH,LO,MART,MVAR )"
                    + " WHERE EXISTS "
                    + " (SELECT 1 FROM ICC_GLLG A LEFT JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + " WHERE ICCGLDAT=:SETDATE AND S.MANDANT=:MANDANT  AND S.MONTH=:MONTH  AND ICCGLLO='FI' AND ICCGLLB='PR' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO  AND S.MART=GPGART  AND S.MVAR=GPGVAR)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    or1.Parameters.Add("SETDATE", OracleType.NVarChar).Value = dwData["SETDATE"].ToString();
                    break;
                case 3:
                    or1.CommandText = "UPDATE ICC_EXSTOCK S SET TR99="
                    + " (SELECT SUM(ICCGLBSTKG ) AS TR99 FROM ICC_GLLG A  JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + " WHERE ICCGLDAT=:SETDATE AND S.MANDANT=:MANDANT  AND S.MONTH=:MONTH  AND ICCGLLO<>'FI' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO AND  S.MART=GPGART  AND S.MVAR=GPGVAR"
                    + "  GROUP BY MANDANT,MONTH,LO,MART,MVAR )"
                    + " WHERE EXISTS "
                    + " (SELECT 1 FROM ICC_GLLG A  JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + " WHERE ICCGLDAT=:SETDATE  AND S.MANDANT=:MANDANT  AND S.MONTH=:MONTH AND ICCGLLO<>'FI'  AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO  AND S.MART=GPGART  AND S.MVAR=GPGVAR)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    or1.Parameters.Add("SETDATE", OracleType.NVarChar).Value = dwData["SETDATE"].ToString();
                    break;
                case 31:
                    or1.CommandText = "UPDATE ICC_EXSTOCK S SET TR99="
                    + " (SELECT SUM(ICCGLBSTKG ) AS TR99 FROM ICC_GLLG A  JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + " WHERE ICCGLDAT=:SETDATE AND S.MANDANT=:MANDANT  AND S.MONTH=:MONTH   AND ICCGLLO='FI' AND ICCGLLB='PR' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO AND  S.MART=GPGART  AND S.MVAR=GPGVAR"
                    + "  GROUP BY MANDANT,MONTH,LO,MART,MVAR )"
                    + " WHERE EXISTS "
                    + " (SELECT 1 FROM ICC_GLLG A  JOIN GPDAT B ON A.ICCGLMANDANT = B.GPMANDANT AND A.ICCGLPARTIE = B.GPPARTIE"
                    + " WHERE ICCGLDAT=:SETDATE  AND S.MANDANT=:MANDANT  AND S.MONTH=:MONTH  AND ICCGLLO='FI' AND ICCGLLB='PR' AND S.MANDANT=ICCGLMANDANT AND S.LO=ICCGLLO  AND S.MART=GPGART  AND S.MVAR=GPGVAR)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    or1.Parameters.Add("SETDATE", OracleType.NVarChar).Value = dwData["SETDATE"].ToString();
                    break;
                case 4:
                    or1.CommandText = "UPDATE ICC_EXSTOCK E SET TR10=(SELECT SUM(GABKG) FROM ICC_MGABEW A"
                    + "  WHERE MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO<>'FI' AND GABBS IN  ('01','10','11','13','21','23','27','41') "
                    + "  AND SUBSTR(GABBUCHDAT,1,6)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO "
                    + "  AND GABART=MART AND GABVAR=MVAR"
                    + "  GROUP BY GABMANDANT,GABLO,GABART,GABVAR )"
                    + " WHERE EXISTS   (  SELECT 1 FROM ICC_MGABEW WHERE "
                    + "   MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO<>'FI' AND GABBS IN ('01','10','11','13','21','23','27','41')"
                    + "   AND SUBSTR(GABBUCHDAT,1,6)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO AND GABART=MART AND GABVAR=MVAR)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 41:
                    or1.CommandText = "UPDATE ICC_EXSTOCK E SET TR10=(SELECT SUM(GABKG) FROM ICC_MGABEW A"
                    + "  WHERE MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO='FI' AND GABLB='PR' AND GABBS IN  ('01','10','11','13','21','23','27','41') "
                    + "  AND SUBSTR(GABBUCHDAT,1,6)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO "
                    + "  AND GABART=MART AND GABVAR=MVAR"
                    + "  GROUP BY GABMANDANT,GABLO,GABART,GABVAR )"
                    + " WHERE EXISTS   (  SELECT 1 FROM ICC_MGABEW WHERE "
                    + "   MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO='FI' AND GABLB='PR' AND GABBS IN ('01','10','11','13','21','23','27','41')"
                    + "   AND SUBSTR(GABBUCHDAT,1,6)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO AND GABART=MART AND GABVAR=MVAR )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 5:
                    or1.CommandText = "UPDATE ICC_EXSTOCK E SET TR11=(SELECT SUM(GABKG) FROM ICC_MGABEW A"
                    + "  WHERE MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO<>'FI' AND GABBS IN ('12','20','26','31','33','35','40','50','51','52')  "
                    + "  AND RTRIM(GABBUCHDAT)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO "
                    + "  AND GABART=MART AND GABVAR=MVAR"
                    + "  GROUP BY GABMANDANT,GABLO,GABART,GABVAR )"
                    + " WHERE EXISTS   (  SELECT 1 FROM ICC_MGABEW WHERE "
                    + "   MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO<>'FI' AND GABBS IN ('12','20','26','31','33','35','40','50','51','52')  "
                    + "  AND RTRIM(GABBUCHDAT)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO AND GABART=MART AND GABVAR=MVAR  )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 51:
                    or1.CommandText = "UPDATE ICC_EXSTOCK E SET TR11=(SELECT SUM(GABKG) FROM ICC_MGABEW A"
                    + "  WHERE MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO='FI' AND GABLB='PR' AND GABBS IN ('12','20','26','31','33','35','40','50','51','52')  "
                    + "  AND RTRIM(GABBUCHDAT)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO "
                    + "  AND GABART=MART AND GABVAR=MVAR"
                    + "  GROUP BY GABMANDANT,GABLO,GABART,GABVAR )"
                    + " WHERE EXISTS   (  SELECT 1 FROM ICC_MGABEW WHERE "
                    + "   MANDANT=:MANDANT AND MONTH=:MONTH AND GABLO='FI' AND GABLB='PR' AND GABBS IN ('12','20','26','31','33','35','40','50','51','52')  "
                    + "  AND RTRIM(GABBUCHDAT)=MONTH AND GABMANDANT=E.MANDANT AND GABLO=LO AND GABART=MART AND GABVAR=MVAR  )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 6:
                    or1.CommandText = "UPDATE ICC_EXSTOCK SET DMOVE=TR10-TR11,DSTOCK=TR00+TR10-TR11-TR99  WHERE   MANDANT=:MANDANT AND MONTH=:MONTH";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
                case 7:
                    or1.CommandText = "UPDATE ICC_EXSTOCK SET DMOVSTOCK=DSTOCK-DMOVE  WHERE   MANDANT=:MANDANT AND MONTH=:MONTH";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("MONTH", OracleType.NVarChar).Value = dwData["MONTH"].ToString();
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
